
file(GLOB INC_FILES "core/include/*.h")
file(GLOB SRC_FILES "core/src/*.cpp")

FIND_PACKAGE(PkgConfig)
INCLUDE(cmake/FindDepend.cmake)

IF (OCR_OUTPUT_LIB)
    MESSAGE(STATUS "--build output library:OCR_OUTPUT_LIB=ON")
	IF (BUILD_STATIC)
		MESSAGE(STATUS "--build output static library:BUILD_STATIC=ON")
		#build setup
		ADD_LIBRARY(RapidOcr_static STATIC ${DbNet} ${AngleNet} ${CrnnNet} ${SRC_FILES})
		SET_TARGET_PROPERTIES(RapidOcr_static PROPERTIES OUTPUT_NAME "RapidOcr")
		SET_TARGET_PROPERTIES(RapidOcr_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
		#link setup
		IF (ENGINE_NCNN)
			MESSAGE(STATUS "--use NCNN engine:ENGINE_NCNN=ON")
			TARGET_LINK_LIBRARIES(RapidOcr_static ${OpenCV_LIBS} ${ncnn_LIBS})
		ELSE()
			MESSAGE(STATUS "--use OnnxRuntime engine！")
			TARGET_LINK_LIBRARIES(RapidOcr_static ${OpenCV_LIBS} ${OnnxRuntime_LIBS})
		ENDIF()
		#设置链接参数
		TARGET_LINK_OPTIONS(RapidOcr_static PRIVATE "-Wl,-rpath,/usr/lib")
		TARGET_COMPILE_DEFINITIONS(RapidOcr_static PRIVATE __CLIB__)
		if (ONNX_USE_CUDA STREQUAL "CUDA")
			TARGET_COMPILE_DEFINITIONS(RapidOcr_static PRIVATE __CUDA__)
		elseif(ONNX_USE_DIRECTML STREQUAL "DIRECTML")
			TARGET_COMPILE_DEFINITIONS(RapidOcr_static PRIVATE __DIRECTML__)
		endif ()

		INSTALL(TARGETS RapidOcr_static ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}")
	ENDIF()
	IF (BUILD_SHARED)
		MESSAGE(STATUS "--build output share library:BUILD_SHARED=ON")
		#build setup
		ADD_LIBRARY(RapidOcr_shared SHARED ${DbNet} ${AngleNet} ${CrnnNet} ${SRC_FILES})
		SET_TARGET_PROPERTIES(RapidOcr_shared PROPERTIES OUTPUT_NAME "RapidOcr")
		SET_TARGET_PROPERTIES(RapidOcr_shared PROPERTIES CLEAN_DIRECT_OUTPUT 1)
		#link setup
		IF (ENGINE_NCNN)
			MESSAGE(STATUS "--static library use NCNN engine:ENGINE_NCNN=ON")
			TARGET_LINK_LIBRARIES(RapidOcr_shared ${OpenCV_LIBS} ${ncnn_LIBS})
		ELSE()
			MESSAGE(STATUS "--static library use OnnxRuntime engine！")
			TARGET_LINK_LIBRARIES(RapidOcr_shared ${OpenCV_LIBS} ${OnnxRuntime_LIBS})
		ENDIF()
		#设置链接参数
		TARGET_LINK_OPTIONS(RapidOcr_shared PRIVATE "-Wl,-rpath,/usr/lib")
		TARGET_COMPILE_DEFINITIONS(RapidOcr_shared PRIVATE __CLIB__)
		if (ONNX_USE_CUDA STREQUAL "CUDA")
			TARGET_COMPILE_DEFINITIONS(RapidOcr_shared PRIVATE __CUDA__)
		elseif(ONNX_USE_DIRECTML STREQUAL "DIRECTML")
			TARGET_COMPILE_DEFINITIONS(RapidOcr_shared PRIVATE __DIRECTML__)
		endif ()
		INSTALL(TARGETS RapidOcr_shared LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}")
	ENDIF()
ENDIF()

IF (OCR_OUTPUT_JNI)
	ADD_LIBRARY(RapidOcr_jni SHARED ${DbNet} ${AngleNet} ${CrnnNet} ${SRC_FILES})
	SET_TARGET_PROPERTIES(RapidOcr_jni PROPERTIES OUTPUT_NAME "RapidOcrJni")
	SET_TARGET_PROPERTIES(RapidOcr_jni PROPERTIES CLEAN_DIRECT_OUTPUT 1)
	#link setup
	IF (ENGINE_NCNN)
		MESSAGE(STATUS "--share library use NCNN engine:ENGINE_NCNN=ON")
		TARGET_LINK_LIBRARIES(RapidOcr_jni ${OpenCV_LIBS} ${ncnn_LIBS} ${JNI_LIBS})
	ELSE()
		MESSAGE(STATUS "--share library use OnnxRuntime engine！")
		TARGET_LINK_LIBRARIES(RapidOcr_jni ${OpenCV_LIBS} ${OnnxRuntime_LIBS} ${JNI_LIBS})
	ENDIF()
    TARGET_COMPILE_DEFINITIONS(RapidOcr_jni PRIVATE __JNI__)
	INSTALL(TARGETS RapidOcr_jni LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}")
endif ()



IF (OCR_OUTPUT_BIN)
	#生成可执行程序设置
	ADD_EXECUTABLE(RapidOcr_bin ${benchmark}
								${AngleNet}
								${CrnnNet}
								${clipper}
								${DbNet}
								${getopt}
								${OcrLiteImpl}
								${OcrLite}
								${OcrUtils}
	)
	SET_TARGET_PROPERTIES(RapidOcr_bin PROPERTIES OUTPUT_NAME "RapidOcr")
	SET_TARGET_PROPERTIES(RapidOcr_bin PROPERTIES CLEAN_DIRECT_OUTPUT 1)
	#链接依赖库
	IF (ENGINE_ONNX)
		TARGET_LINK_LIBRARIES(RapidOcr_bin ${OpenCV_LIBS} onnxruntime )
	ELSEIF (ENGINE_NCNN)
		TARGET_LINK_LIBRARIES(RapidOcr_bin ${OpenCV_LIBS} ncnn )
	ENDIF()
	#设置链接参数
	TARGET_LINK_OPTIONS(RapidOcr_bin PRIVATE "-Wl,-rpath,/usr/lib")
    TARGET_COMPILE_DEFINITIONS(RapidOcr_bin PRIVATE __EXEC__)
	INSTALL(TARGETS RapidOcr_bin RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
ENDIF()

file(GLOB CORE_INC "core/include/*.h")
install(FILES ${CORE_INC} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}/core")
